﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.IO;
using System.Web.Http;
using ExpenseSystem.Core;
using ExpenseSystem.Core.Authority;
using ExpenseSystem.Core.Converter;
using ExpenseSystem.Core.FiscalPeriodModules;
using ExpenseSystem.Fether;
using ExpenseSystem.Common;
using ExpenseSystem.Lor;
using ExpenseSystem.Model;
using ExpenseSystem.Common.BaseModel;


namespace ExpenseSystem.Controllers
{
    [RoutePrefix("api/FiscalPeriod")]
    public class FiscalPeriodController : ApiController
    {
        readonly SetInhibition setInhibition;
        readonly GetInhibition getInhibition;
        SetInhibitionMaker inhibitionMaker = new StateInhibitionMaker();
        GetInhibitionMaker getInhibitionMaker = new GetInhibitionMaker();
        public FiscalPeriodController()
        {
            setInhibition = inhibitionMaker.Make();
            getInhibition = getInhibitionMaker.Make();
        }

        readonly FiscalPeriodFetcher fetcher = new FiscalPeriodFetcher();
        readonly FiscalPeriodManager manager = FiscalPeriodManager.CreateInstance();
        [Route("GetBySite")]
        [HttpGet]
        public ResponseModel Get()
        {
            UserProfile userProfile = Authority.GetUserProfile();
            Restrain restrain = Restrain.Eq("Site",userProfile.SiteId);
            return NormalControllerHelper.List(fetcher, "BAS_FISCALPERIOD_LIST", new Restrain[] { restrain },null, getInhibition);
        }

        [Route("Set")]
        [HttpPost]
        public ResponseModel Set(FiscalPeriodModel data)
        {
            return NormalControllerHelper.Set(fetcher, "BAS_FISCALPERIOD_SET", data, manager, setInhibition, getInhibition);
        }
    }
}
